@extends('home.layout.base')
@section('title', '申请友情链接')
@section('pluginstyle')
<link rel="stylesheet" href="{{ asset('/dist/home/css/links.css') }}" />
<link rel="stylesheet" href="{{ asset('/common/css/common.css') }}" />
@endsection
@section('content')
<div class="w" style="max-width: 1240px;margin:0 auto;">
    <div class="link_box">
        <div class="link_top"><div class="top_right"></div><div class="top_left"></div></div>	
        <div class="link_content">
            <h3 class="link_tit">友情链接</h3>
            <ul class="link_list">
                @foreach($linksList as $link)
                <li><a href="{{ $link->link_url }}" target="_blank">{{ $link->link_name }}</a></li>
                @endforeach
            </ul>
            <div class="Pagination">
                {!! $linksList->render() !!}
            </div>
        </div>
        <div class="link_bottom"><div class="bottom_right"></div><div class="bottom_left"></div></div>
    </div>
    <div class="link_box_a">
        <div class="link_top">
            <div class="top_right"></div>
            <div class="top_left"></div>
        </div>
        <div class="link_content">
            <h3 class="link_tit">申请友情链接</h3>
            <ul class="link_step">
                <li class="link_step_tit">申请步骤：</li>
                <li>
                    <div class="float_Left">
                        1.</div>
                    <div class="margin_l_12">
                        请先在贵网站做好{{ Config::get('web.web_title') }}的文字友情链接：
                        <br> 链接文字：{{ Config::get('web.web_title') }}链接地址：
                        <a href="{{ Config::get('web.web_domain') }}" target="_blank">{{ Config::get('web.web_domain') }}</a></div>
                </li>
                <li>2.做好链接后，请在右侧填写申请信息。{{ Config::get('web.web_title') }}只接受申请文字友情链接。</li>
                <li>
                    <div class="float_Left"> 3.</div>
                    <div class="margin_l_12">
                        已经开通我站友情链接且内容健康，符合本站友情链接要求的网站，经管理员审核后，可以显示在此友情链接页面。</div>
                </li>
                <li>
                    <div class="float_Left"> 4.</div>
                    <div class="margin_l_12">
                        请通过右侧提交申请。</div>
                </li>
            </ul>
            <form id="frm_submit">
                <table cellpadding="0" cellspacing="0" class="link_table" width="309">
                    <tbody>
                        <tr>
                            <td height="29" colspan="2" valign="top" class="link_step_tit">
                                申请信息</td>
                        </tr>
                        <tr>
                            <td height="29">
                                网站名称：
                            </td>
                            <td height="29">
                                <input id="link_name" name="link_name" type="text" class="w247">
                            </td>
                        </tr>
                        <tr>
                            <td height="29">
                                网&nbsp;&nbsp;&nbsp;&nbsp;址：
                            </td>
                            <td height="29">
                                <input id="link_url" name="link_url" type="text" class="w247" value="http://">
                            </td>
                        </tr>
                        <tr>
                            <td width="61" height="29" valign="top">
                                网站介绍：
                            </td>
                            <td width="348" valign="top">
                                <textarea id="link_desc" name="link_desc" cols="" rows="" class="w247h60"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td height="45" colspan="2" align="center" valign="middle">
                                <input type="button" value="提交申请" id="btnSubmit" class="link_button">
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>
        <div class="link_bottom">
            <div class="bottom_right"></div>
            <div class="bottom_left"></div>
        </div>
    </div>
</div>
@endsection
@section('pluginscript')
<script type="text/javascript">
$(function(){
    function addLinks(){
        var data = {};
        data._token = "{{ csrf_token() }}";
        data.link_name = $('#link_name').val().trim();
        data.link_url = $('#link_url').val().trim();
        data.link_desc = $('#link_desc').val().trim();
        
        if(data.link_name == ''){
            qikoo.dialog.alert('网站名称不能为空');
            return false;
        }
        if(data.link_url == ''){
            qikoo.dialog.alert('网站链接不能为空');
            return false;
        }
        // TODO 链接正则匹配
        
        $.post("{{ url('/links') }}", data, function(msg){
            qikoo.dialog.alert(msg.info);
            if(msg.status == 1){
                location.href = "{{ url('/') }}";
            }
        });
    }
   $('#frm_submit').submit(function(){
       addLinks();
   });
   $('#btnSubmit').click(function(){
       addLinks();
   });
});
</script>
@endsection